/**
 * Created by zyh on 2019/9/4.
 */

const axiosFun = function axiosFun(url, method = 'POST', data, fun) {
  axios({
    method: method,
    url: url,
    params: method == 'POST' ? null : data,
    data: data,
    responseType: 'json',
    withCredentials: true,
  }).then(res => {
    fun(res)
  }).catch(err => {
    fun(res)
  })
}

const baseUpdate = function () {
  var base = $('#base').val().trim();
  localStorage.setItem('baseURL', base)
}

const numberUpdate = function () {
  var number = $('#number').val().trim();
  localStorage.setItem('number', number)
}

const toJson = function (str) {
  var res = '';
  if (str != '' && str != undefined && str != null) {
    if (typeof str == 'string') {
      str = str.trim();
      res = JSON.parse(str) ? JSON.parse(str) : eval('(' + str + ')');
    } else if (typeof str == 'object') {
      res = str;
    }
  }
  return res;
};

const toStr = function (obj) {
  var res = '';
  if (typeof obj == 'string') {
    res = obj;
  } else if (typeof obj == 'object') {
    res = JSON.stringify(obj);
  }
  return res;
};
